<!--extend frame-->
<block_title>
    脚手架
</block_title>
<block_left>
    <a href="{{url SysNaples/Admin/scaffolding/map}}" class="list-group-item"><span class="glyphicon glyphicon-map-marker"><span class="hidden-xs bold"> 网站导览</span></span></a>
    <a href="{{url SysNaples/Admin/scaffolding/module}}" class="list-group-item"><span class="glyphicon glyphicon-book"><span class="hidden-xs bold"> 创建模块</span></span></a>
    <a href="{{url SysNaples/Admin/scaffolding/controller}}" class="list-group-item"><span class="glyphicon glyphicon-list-alt"><span class="hidden-xs bold"> 创建控制器</span></span></a>
    <a href="{{url SysNaples/Admin/scaffolding/model}}" class="list-group-item"><span class="glyphicon glyphicon-record"><span class="hidden-xs bold"> 创建CURD</span></span></a>
    <a href="{{url SysNaples/Admin/scaffolding/fastEdit}}" class="list-group-item"><span class="glyphicon glyphicon-pencil"><span class="hidden-xs bold"> 快速编辑测试页</span></span></a>
</block_left>
<block_right>
    {{if $action=='module'}}
        <div class="panel panel-primary center-block" style="max-width: 700px;min-height: 200px;margin-top: 100px">
            <div class="panel-heading">
                <h3 class="panel-title">创建一个模块所需要的基本文件结构</h3>
            </div>
            <div class="panel-body">
                <form action="" method="post" class="form-horizontal" role="form" onsubmit="return false;">
                    <div class="form-group">
                        <label for="ipt-module-name" class="col-sm-2 control-label">模块名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="ipt-module-name" placeholder="Module">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-10 col-sm-offset-2">
                            <button type="submit" id="btn-sub-module" class="btn btn-primary">创建</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <script>
            $(function () {
                $('#btn-sub-module').click(function () {
                    var moduleName=$('#ipt-module-name').val();
                    $.ajax({
                        type: "POST",
                        url: "{{url SysNaples/Admin/createModule}}",
                        data: {
                            'moduleName':moduleName
                        },
                        dataType: "json",
                        async:false,

                        success: function(data){
                            alert(data.msg);
                            location.href='{{url SysNaples/Admin/scaffolding/map}}';
                        },
                        error:function () {
                            alert('错误，远程服务器没有响应.')
                        }
                    });
                })
            })
        </script>
    {{elseif $action=='controller'}}
        <div class="panel panel-primary" style="margin-left: 200px;max-width: 700px;min-height: 200px;margin-top: 100px">
        <div class="panel-heading">
            <h3 class="panel-title">搭建一个控制器</h3>
        </div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" onsubmit="return false;">
                <div class="form-group">
                    <label for="ctrlName" class="col-sm-2 control-label">控制器名</label>
                    <div class="col-sm-10">
                        <input type="text" required class="form-control" id="ctrlName" placeholder="ctrlName">
                    </div>
                </div>
                <div class="form-group">
                	<label for="slt-module" class="col-sm-2 control-label">所属模块</label>
                	<div class="col-sm-10">
                		<select name="name" id="slt-module" class="form-control">
                            {{each $modules}}
                                <option value="{{:v}}">  {{:v}}  </option>
                            {{/}}
                        </select>
                	</div>
                </div>
                <!--action begin-->
                <div class="panel panel-info hidden" id="copyMe">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <span class="btn btn-xs btn-info btn-hideAction" style="width:30px;">-</span>
                            <span class="btn btn-xs btn-info btn-showAction hidden" style="width:30px;">+</span>
                            <span class="btn btn-xs btn-danger btn-delAction" style="width:30px;">X</span>
                            &nbsp;&nbsp;&nbsp;&nbsp; 动作
                            <span class="display-action"></span>
                        </h3>
                    </div>
                    <form action="" method="post" class="form-horizontal" role="form">
                        <br/>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">动作名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control ipt-actionName" placeholder="actionName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">添加注释</label>
                            <div class="col-sm-10">
                                <textarea class="form-control ipt-actionDoc" spellcheck="false" style="height:100px;" placeholder="添加注释，不需要写/**/标记"></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">模板引擎</label>
                            <div class="col-sm-10">
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="name" value="none" checked="checked">
                                        无
                                    </label>
                                    &nbsp;&nbsp;
                                    <label>
                                        <input type="radio" name="name" value="naples">
                                        naples模板页面
                                    </label>
                                    &nbsp;&nbsp;
                                    <label>
                                        <input type="radio" name="name" value="php" >
                                        原生php页面
                                    </label>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="clearfix"></div>
                </div>
                <!--action end-->
                <div id="action-panels">

                </div>


                <div class="btn-group pull-right" style="margin-top: 30px">
                    <button type="button" id="btn-add-action" class="btn btn-info">添加action</button>
                    <button type="button" id="btn-submit-ctrl" class="btn btn-primary">确定</button>
                </div>
                <div class="btn-group pull-right" style="margin-top: 30px;margin-right: 10px">
                    <button type="button" class="btn btn-danger" onclick="history.go(0)">清空</button>
                </div>
            </form>
            <script>
                $(function () {
                    $('#btn-add-action').click(function () {
                        var copyMe=$('#copyMe');
                        var clone=copyMe.clone(true);
                        clone.removeClass('hidden');
                        clone.removeAttr('id');
                        clone.find('input:radio').attr('name','slt'+Math.random());
                        $('#action-panels').append(clone);
                    });
                    $('.btn-delAction').on('click',function () {
                        $(this).parent().parent().parent().remove();
                    });
                    $('.btn-showAction').on('click',function () {
                        $(this).parent().parent().parent().find('.form-group').slideDown();
                        $(this).addClass('hidden');
                        $(this).siblings('.btn-hideAction').removeClass('hidden');
                    });
                    $('.btn-hideAction').on('click',function () {
                        $(this).parent().parent().parent().find('.form-group').slideUp();
                        $(this).addClass('hidden');
                        $(this).siblings('.btn-showAction').removeClass('hidden');
                    });
                    $('.ipt-actionName').on('keyup',function () {
                        var name=$(this).val();
                        $(this).parent().parent().parent().find('.display-action').html(name);
                    });
                    $('#btn-submit-ctrl').click(function () {
                       //在此整理数据准备提交
                        var ctrlName=$('#ctrlName').val();
                        var slt_module=$('#slt-module').val();
                        var actionPanels=$('#action-panels .panel');
                        var actions=[];
                        actionPanels.each(function () {
                            actions.push({
                               'actionName':$(this).find('.ipt-actionName').val(),
                               'actionDoc':$(this).find('.ipt-actionDoc').val(),
                               'tplEngine':$(this).find('input:radio:checked').val(),
                            });
                        });
                        var data={
                            'ctrlName':ctrlName,
                            'moduleName':slt_module,
                            'actions':actions,
                        };
//                        console.log(data);
                        $.ajax({
                            type: "POST",
                            url: "{{url SysNaples/Admin/createCtrl}}",
                            data: data,
                            dataType: "json",
                            async:false,

                            success: function(data){
                                alert(data.msg);
                                location.reload(true);
                            },
                            error:function () {
                                alert('错误，远程服务器没有响应.')
                            }
                        });
                    });
                })
            </script>
        </div>
    </div>
    {{elseif $action=='map'}}
        <div class="container-fluid" id="box-map">
            {{each $modules $module}}
            <div class="panel panel-primary maps">
            	  <div class="panel-heading">
            			<h3 class="panel-title">
                            <span class="btn btn-xs btn-info btn-hidePanel hidden" style="width:30px;">-</span>
                            <span class="btn btn-xs btn-info btn-showPanel " style="width:30px;">+</span>
                            <span class="btn btn-xs btn-danger btn-delPanel" style="width:30px;">X</span>
                            {{:module.moduleName}}
                        </h3>
            	  </div>
            	  <div class="panel-body">
                      <!-- TAB NAVIGATION -->
                      <ul class="nav nav-tabs" role="tablist">
                          {{each $module['ctrls'] $ctrl}}
                          <li class=""><a href="#tab_{{:module.moduleName}}_{{:ctrl.ctrlName}}" role="tab" data-toggle="tab"> {{:ctrl.ctrlName}}</a></li>
                          {{/}}
                      </ul>
                      <!-- TAB CONTENT -->
                      <div class="tab-content">
                          {{each $module['ctrls'] $ctrl}}
                          <div class="tab-pane fade in" id="tab_{{:module.moduleName}}_{{:ctrl.ctrlName}}">
                              <table class="table table-bordered table-hover">
                              	<thead>
                              		<tr>
                              			<th>动作</th>
                              			<th>参数</th>
                              			<th>注释</th>
                              		</tr>
                              	</thead>
                              	<tbody>
                                {{each $ctrl['infos'] $info}}
                              		<tr>
                                        <td><a href="{{:info.url}}" target="_blank">{{:info.name}}</a></td>
                              			<td>{{:info.params}}</td>
                              			<td>{{:info.doc}}</td>
                              		</tr>
                                {{/}}
                              	</tbody>
                              </table>
                          </div>
                          {{/}}
                      </div>

                  </div>
            </div>
            {{/}}
        </div>

        <script>
            //脚本
            $(function () {
                $('#box-map').find('.nav').each(function () {
                    $(this).find('li:first').addClass('active')
                });
                $('#box-map').find('.tab-content').each(function () {
                    $(this).find('.tab-pane:first').addClass('active')
                });
                $('.maps .panel-body').toggle();
                $('.btn-delPanel').on('click',function () {
                    $(this).parent().parent().parent().remove();
                });
                $('.btn-showPanel').on('click',function () {
                    $(this).parent().parent().parent().find('.panel-body').slideDown();
                    $(this).addClass('hidden');
                    $(this).siblings('.btn-hidePanel').removeClass('hidden');
                });
                $('.btn-hidePanel').on('click',function () {
                    $(this).parent().parent().parent().find('.panel-body').slideUp();
                    $(this).addClass('hidden');
                    $(this).siblings('.btn-showPanel').removeClass('hidden');
                });
            })
        </script>
    {{elseif $action=='fastEdit'}}
        <!--快速编辑测试页-->

        <div class="row" style="margin-top: 20px">
        	<div class="col-md-6">
                <form onsubmit="return false" action="#" method="post" role="form">
                	<legend  style="border: none">
                        编辑php脚本
                        <button  data-toggle="modal" href="#modal-tmp" class="btn btn-primary btn-sm" id="btn-tmp">草稿纸</button>
                    </legend>
                    <div class="modal fade" id="modal-tmp">
                    	<div class="modal-dialog">
                    		<div class="modal-content">
                    			<div class="modal-header">
                    				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    				<h4 class="modal-title">草稿纸</h4>
                    			</div>
                    			<div class="modal-body">
                    				<textarea id="txt-tmp" spellcheck="false" style="height:550px;width: 100%;resize: none">{{:tmp}}</textarea>
                    			</div>
                    			<div class="modal-footer">
                    				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    				<button type="button" class="btn btn-primary" id="btn-save-tmp" data-dismiss="modal">保存</button>
                    			</div>
                    		</div><!-- /.modal-content -->
                    	</div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->
                    <div class="form-group">
                        <label></label>
                        <iframe id="ifm-edit" name="ifm-edit" src="{{url fastEditMirror based}}" class="form-control" style="height:550px;resize: none"></iframe>
                    </div>
                </form>
        	</div>
            <div class="col-md-6">
                <form onsubmit="return false" action="#" method="post" role="form">
                    <legend style="border: none">
                        <button type="submit" class="btn btn-primary btn-sm" id="btn-f5">刷新脚本运行结果(F5)</button>
                    </legend>
                    <div class="form-group">
                        <label></label>
                        <iframe id="ifm-rel" src="" class="form-control" style="height:550px;resize: none"></iframe>
                    </div>
                </form>
            </div>
        </div>
        <script>
            $(function () {
                $('#btn-f5').click(function () {
                    $('#ifm-rel').attr('src','{{url fastEdit based}}');
                });
                //屏蔽F5
                document.onkeydown = function(e){
                    e = window.event || e;
                    var keycode = e.keyCode || e.which;
                    if(keycode==116){
                        flash();
                        if(window.event){// ie
                            try{e.keyCode = 0;}catch(e){}
                            e.returnValue = false;
                        }else{// ff
                            e.preventDefault();
                        }
                    }
                };

                $("#btn-save-tmp").click(function () {
                    $.ajax({
                        type: "POST",
                        url: "{{url fastEditTmpSub based}}",
                        data: {
                            tmp:$("#txt-tmp").val()
                        },
                        dataType: "json",
                        async:true,

                        success: function(data){
                            //刷新了
                        },
                        error:function () {
                            alert('错误，远程服务器没有响应.')
                        }
                    });
                })
            });

            function flash() {
                //触发刷新
                $('#btn-f5').click();
            }
        </script>
    {{elseif $action=='model'}}
        <!--生成CURD代码-->
        {{if $step==1}}
            {{inc scaffolding-step1}}
        {{elseif $step==2}}
            {{inc scaffolding-step2}}
        {{elseif $step==3}}
            {{inc scaffolding-step3}}
        {{elseif $step==4}}
            {{inc scaffolding-step4}}
        {{/}}

    {{else}}
    <div class="container">
        <div class="jumbotron" style="background-color: inherit">
            <h2>脚手架工具</h2>
            <p>请于左侧选择一项功能。</p>
        </div>
    </div>
    {{/}}

</block_right>
<block_bottom>

</block_bottom>
